package kuanshu.controller;

// 允许其他项目访问
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import kuanshu.bean.YongHuXinXi;
import kuanshu.mapper.YongHuXinXiMapper;
import kuanshu.util.JsonResult;

@CrossOrigin("*")
@RestController
@RequestMapping("/yonghuxinxi")
public class YongHuXinXiController {
    @Resource
    public YongHuXinXiMapper yongHuXinXiMapper;

    @RequestMapping("/login")
    public JsonResult denglu(YongHuXinXi yongHuXinXi) { // 参数
        System.out.println(yongHuXinXi);
        YongHuXinXi u = yongHuXinXiMapper.denglu(yongHuXinXi);
        System.out.println(u);
        if (u == null) {
            // 登陆失败
            JsonResult result = new JsonResult(false, 427, null, "账号或者密码错误");
            return result;
        } else {
            // 登陆成功 将用户登陆信息给前端送过来，这里假设使用 yonghuming 作为返回信息
            JsonResult result = new JsonResult(true, 200, u.getYonghuming(), "登陆成功");
            // 保存下来，当前登录信息
            return result;
        }
    }

    @RequestMapping("/add")
    public JsonResult add1(YongHuXinXi yongHuXinXi) {
        int rows = yongHuXinXiMapper.add(yongHuXinXi);
        if (rows > 0) {
            JsonResult jsonResult = new JsonResult(true, 200, "success", "");
            return jsonResult;
        } else {
            JsonResult jsonResult = new JsonResult(false, 500, "注册失败", "");
            return jsonResult;
        }
    }
}